package com.ruoyi.web.api;

import org.openapi.consts.EventType;
import org.openapi.service.IApiLoaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 启动加载api模型和配置
 */
@Component
public class ApiRunner implements ApplicationRunner {
    @Autowired
    private IApiLoaderService apiLoaderService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        apiLoaderService.decideDb();
        apiLoaderService.loadModel();
        apiLoaderService.loadEvent();
        apiLoaderService.loadSql();
        apiLoaderService.loadExchange();

        //注册审批回调，同步更新关联业务的状态
        apiLoaderService.on("flow_task", EventType.AU.getCode());
        //注册采购主表回调，标记采购完成前验证是否全部入库
        apiLoaderService.on("asset_purchase", EventType.BU.getCode());
    }
}
